package tests;

import org.testng.Assert;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

/**
 * Created by WHOover on 18.06.2014.
 */
public class Homework3 {
    @Parameters({"arrayString"})
    @Test
    public void yourTest(String arrayString) {
        String[] sortedArrayParameter = arrayString.split(", ");
        int[] array = {8, 5, 3, 0, 9, 6, 2, 1, 7, 4};
        int size = 10;
        int[] sortedArray = arraySort(array, size);

        for ( int i = 0; i < size; i++ ) {
            if (Integer.parseInt((sortedArrayParameter[i])) == sortedArray[i]) {
                System.out.println("At index " + i + "(paramArray == myArray): " + Integer.parseInt((sortedArrayParameter[i])) +
                                   " == " + sortedArray[i] + "; PASSED");
            } else {
                System.out.println("At index " + i + "(paramArray == myArray): " + Integer.parseInt((sortedArrayParameter[i])) +
                        " != " + sortedArray[i] + "; FAILED");
                Assert.assertEquals(Integer.parseInt((sortedArrayParameter[i])), sortedArray[i]);
            }
        }
    }

    public int[] arraySort(int[] array, int size) {
        for ( int i = 0; i < size; i++ ) {
            int minIndex = i;
            int buffer;

            for ( int j = i + 1; j < size; j++ ) {
                if ( array[j] < array[minIndex] ) {
                    minIndex = j;
                }
            }
            buffer = array[minIndex];
            for ( int j = minIndex; j > i; j-- ) {
                array[j] = array[j-1];
            }
            array[i] = buffer;
        }

        return array;
    }
}
